package com.acwebsitedesign.uRateDrugs.domain;

import java.util.List;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration( { "/spring-service.xml" } )
public class DrugServiceTestIntegration {
	
	@Autowired
	DrugService drugService;
	
	@Test
	public void insertDrug(){
		Drug drug = new Drug();
		drug.setName("Test Drug");
		drug.setClassOfDrug("None");
		drug.setWhyIsThisMedicationPrescribed("It isn't");
		drug.setOtherBrands("Air");
		drug.setSideEffects("waste of money");
		drug.setWarnings("not any");
		drug.setTreats("hypcondriacs");
		drugService.saveDrug(drug);
	}
	
	@Test
	public void getDrugByName(){
		String name = "Test Drug";
		List <Drug> drugList = drugService.getDrugByName(name);
		System.out.println("Get drug by name list size = " + drugList.size());
	}
	
	@Test
	public void getDrugById(){
		String name = "Test Drug";
		List<Drug> drugList = drugService.getDrugByName(name);
		Drug drug = drugList.get(0);
		int id = drug.getId();
		@SuppressWarnings("unused")
		List <Drug> drugList2 = drugService.getDrugById(id);
	}
	
	@Test 
	public void updateDrug(){
		String name = "Test Drug";
		List<Drug> drugList = drugService.getDrugByName(name);
		Drug drug = drugList.get(0);
		drug.setClassOfDrug("Great");
		drugService.saveDrug(drug);
	}
	
	
	@Test 
	public void removeDrugById(){
		String name = "Test Drug";
		List<Drug> drugList = drugService.getDrugByName(name);
		Drug drug = drugList.get(0);
		int id = drug.getId();
		drugService.removeDrugById(id);
	}
	
	@Test
	public void removeDrugByName(){
		
		Drug drug = new Drug();
		String name = "Test Drug";
		drug.setName(name);
		drug.setClassOfDrug("None");
		drug.setWhyIsThisMedicationPrescribed("It isn't");
		drug.setOtherBrands("Air");
		drug.setSideEffects("waste of money");
		drug.setWarnings("not any");
		drug.setTreats("hypcondriacs");
		drugService.saveDrug(drug);
		drugService.removeDrugByName(name);
	}
}
